/*
 * @Author: heinan
 * @Date: 2023-07-27 16:50:37
 * @Last Modified by: heinan
 * @Last Modified time: 2023-08-02 09:42:53
 */
const { Service } = require("egg");
const fs = require("fs");
const path = require("path");
const { EMAIL_FORM_NAME } = require("../config");
const { resetPasswordEmailHtml } = require("../utils/resetPasswordEmailHtml");
const { emailTransporter } = require("../utils");

class CommonService extends Service {
  async upload(filepath, filename) {
    const file = fs.readFileSync(filepath);
    const uploadPath = path.join(process.cwd(), "app/public/upload", filename);
    return fs.writeFileSync(uploadPath, file);
  }
  async email({ id, email, subject }) {
    return await emailTransporter.sendMail({
      from: EMAIL_FORM_NAME,
      to: email,
      subject: subject || "Hello ✔",
      // text: text || "Hello world?",
      html: resetPasswordEmailHtml(id),
    });
  }
}
module.exports = CommonService;
